import axios from "axios";
import qs from 'qs';

const instance = axios.create({
    baseURL: 'http://47.93.101.203',
    timeout: 10000,
});
instance.interceptors.request.use(function(config) {
    // token拼接
    if (sessionStorage.getItem('token')) { //当token已经生成代表用户已经登录 在获取数据直接拼接token
        config.headers = ({ 'Authori-zation': 'Bearer ' + sessionStorage.getItem('token') })
    }

    // config.data = (config.data instanceof FormData) ? config.data : qs.stringify(config.data);

    return config;
}, function(error) {
    return Promise.reject(error);
});

instance.interceptors.response.use(function(response) {
    return response.status == 200 ? response.data : response;
}, function(error) {
    return Promise.reject(error);
});

export default instance